#define _CRT_SECURE_NO_WARNINGS
#include"Heap.h"
void TopK(const char* f, int top)
{
	int* topk = (int*)malloc(sizeof(int) * top);
	FILE* fl = fopen(f, "r");
	for(int i=0;i<top;++i)
	{
		fscanf(fl, "%d", &topk[i]);
	}
	for (int i = (top-2)/2; i>=0; --i)
	{
		DownAdjust(topk, top, i);
	}

	int val = 0;
	int ret = fscanf(fl, "%d", &val);
	while (ret != EOF)
	{
		if (val > topk[0])
		{
			topk[0] = val;
			DownAdjust(topk, top, 0);
		}

		ret = fscanf(fl, "%d", &val);
	}
	for (int i = 0; i < top; i++)
		printf("%d \n", topk[i]);
	printf("\n");
	free(topk);
	fclose(fl);
}
int main()
{
	const char* f = "data.txt";
	srand(time(NULL));
	FILE* fl = fopen(f, "w");
	
	for (int i = 0; i < N; i++)
	{
		fprintf(fl, "%d\n", rand() % 10000);
	}
	TopK(f, 10);
	return 0;
}